﻿package idv.etrex.compression 
{
	import idv.etrex.display.XGraphics;
	/**
	 * 用來作lineTo的減少取樣
	 * @author etrex
	 */
	public class XGraphicsDownsampler
	{
		public var xg:XGraphics;
		public function XGraphicsDownsampler(xg:XGraphics) 
		{
			this.xg = xg;
		}
		
		public function downSample(sampleRate:uint):XGraphics {
			var newX:XML = <XGraphics/>;
			var count:int = 0;
			for each(var x:XML in xg.xml.*)
			{
				if (x.name() == "lineTo")
					count++;
				else
					count = 0;
				if (count == sampleRate)
					count = 0;
				if (count == 0)
					newX.appendChild(x);
			}
			return new XGraphics(newX);
		}
	}

}